(function(){"use strict";BX.namespace("BX.Translate");if(BX.Translate.PathList){return}var t=function(){this.actionMode="";this.tabId="";this.gridId="";this.filterId="";this.mode="";this.relUrl="";this.messages={};this.viewMode=[];this.defaults={}};t.prototype.VIEW_MODE={CountPhrases:"CountPhrases",CountFiles:"CountFiles",UntranslatedPhrases:"UntranslatedPhrases",UntranslatedFiles:"UntranslatedFiles",HideEmptyFolders:"HideEmptyFolders",ShowDiffLinks:"ShowDiffLinks"};t.prototype.STYLES={gridLink:"translate-link-grid",editLink:"translate-link-edit",startIndexLink:"translate-start-indexing",menuItem:"translate-menu-item",menuItemChecked:"menu-popup-item-accept"};t.prototype.ACTIONS={fileList:"FILE_LIST",searchFile:"SEARCH_FILE",searchPhrase:"SEARCH_PHRASE"};t.prototype.init=function(t){t=t||{};t.defaults=t.defaults||{};if(!BX.type.isNotEmptyString(t.relUrl))throw"BX.Translate.PathList: 'relUrl' parameter missing.";if(!BX.type.isNotEmptyString(t.defaults.startingPath))throw"BX.Translate.PathList: 'defaults.startingPath' parameter missing.";if(!BX.type.isNotEmptyString(t.tabId))throw"BX.Translate.PathList: 'tabId' parameter missing.";if(!BX.type.isNotEmptyString(t.gridId))throw"BX.Translate.PathList: 'gridId' parameter missing.";if(!BX.type.isNotEmptyString(t.filterId))throw"BX.Translate.PathList: 'filterId' parameter missing.";if(BX.type.isNotEmptyString(t.mode)){this.mode=t.mode}if(BX.type.isNotEmptyString(t.actionMode)){this.actionMode=t.actionMode}else{this.actionMode=this.ACTIONS.fileList}this.defaults=t.defaults;this.relUrl=t.relUrl;this.tabId=t.tabId;this.gridId=t.gridId;this.filterId=t.filterId;if(BX.type.isArray(t.styles)){this.STYLES=BX.mergeEx(this.STYLES,t.styles)}if(BX.type.isArray(t.viewMode)){this.viewMode=t.viewMode}else{this.viewMode.push(this.VIEW_MODE.CountPhrases)}if(BX.type.isPlainObject(t.messages)){this.messages=t.messages}if(BX.type.isArray(t.extraMenuItems)){r=t.extraMenuItems}setTimeout(BX.proxy(this.loadGridParams,this),100);setTimeout(BX.proxy(this.initGridLinks,this),120);BX.addCustomEvent("Grid::updated",BX.delegate(this.initGridLinks,this));BX.addCustomEvent("Grid::updated",BX.delegate(this.loadGridParams,this));BX.addCustomEvent("BX.Main.Filter:beforeApply",BX.delegate(this.filterBeforeApply,this));BX.addCustomEvent("onAjaxFailure",BX.delegate(function(t,e,i){if(t=="auth"){if(typeof this=="object"&&typeof this.filterId!="undefined"){BX.UI.Notification.Center.notify({content:this.getMessage("AuthError")});top.location=top.location.href}}else if(t=="status"){if(typeof i=="object"&&typeof i.xhr=="object"&&i.xhr instanceof XMLHttpRequest){try{var s=JSON.parse(i.xhr.responseText);if(BX.type.isPlainObject(s)){if(s.status==="error"){if(s.errors[0]){BX.UI.Notification.Center.notify({content:s.errors[0].message})}}}}catch(t){}}}},this));BX.Event.EventEmitter.subscribe(BX.UI.StepProcessing.ProcessEvent.BeforeRequest,BX.delegate(function(t){var e=t.data.process?t.data.process:{};var i=t.data.actionData?t.data.actionData:{};if(e instanceof BX.UI.StepProcessing.Process){e.setParam("path",this.getCurrentPath());e.method="POST"}if(i instanceof FormData){i.append("path",this.getCurrentPath());i.append("tabId",this.tabId);i.append("AJAX_CALL","Y");if(this.mode=="admin"){i.append("admin_section","Y");i.append("lang",BX.message("LANGUAGE_ID"))}}else{i["path"]=this.getCurrentPath();i["tabId"]=this.tabId;i["AJAX_CALL"]="Y";if(this.mode=="admin"){i["admin_section"]="Y";i["lang"]=BX.message("LANGUAGE_ID")}}},this));var e=BX("bx-translate-mode-menu-view-anchor");if(e){BX.bind(e,"click",BX.proxy(this.showViewModeMenu,this))}var i=BX("bx-translate-init-folder");if(i){BX.bind(i,"click",BX.proxy(this.showInitFolderMenu,this))}var s=BX("bx-translate-extra-menu-anchor");if(s){BX.bind(s,"click",BX.proxy(this.showExtraMenu,this))}BX.addCustomEvent("Grid::beforeRequest",BX.delegate(this.onBeforeGridRequest,this));BX.bind(window,"popstate",BX.proxy(this.onPopState,this));this.replaceAddressLink(null)};t.prototype.setActionMode=function(t){if(BX.type.isNotEmptyString(t)){this.actionMode=t}return this};t.prototype.getActionMode=function(){return this.actionMode};t.prototype.getMessage=function(t){return BX.type.isNotEmptyString(this.messages[t])?this.messages[t]:""};var e;t.prototype.getFilter=function(){if(typeof e!=="object"||!e instanceof BX.Main.Filter){if(this.filterId!==""&&typeof BX.Main.filterManager!=="undefined"){e=BX.Main.filterManager.getById(this.filterId)}}if(typeof e==="object"&&e instanceof BX.Main.Filter){return e}return null};t.prototype.filterBeforeApply=function(t,e,i,s){if(t==this.filterId){var n,r;if(e.action=="clear"){n=this.defaults.startingPath;var a=this.getFilter().getSearch().getInput();a.value=this.defaults.startingPath}else if(e.action=="apply"){var o=this.getFilter().getFilterFieldsValues();n=o.FIND;n=n.replace(/[\\]+/gi,"/");if(BX.type.isNotEmptyString(o.PHRASE_TEXT)&&!BX.type.isNotEmptyString(o.LANGUAGE_ID)){o.LANGUAGE_ID=BX.message("LANGUAGE_ID")}if(BX.type.isNotEmptyString(o.PHRASE_TEXT)&&!BX.type.isNotEmptyString(o.PHRASE_ENTRY)){if(this.defaults.PHRASE_ENTRY)o.PHRASE_ENTRY=this.defaults.PHRASE_ENTRY}if(BX.type.isNotEmptyString(o.PHRASE_CODE)&&!BX.type.isNotEmptyString(o.CODE_ENTRY)){if(this.defaults.CODE_ENTRY)o.CODE_ENTRY=this.defaults.CODE_ENTRY}this.getFilter().getApi().setFields(o)}r=this.addLinkParam(this.getCurrentUrl(),"path",n);r=this.addLinkParam(r,"tabId",this.tabId);this.replaceAddressLink(r,n,o)}};t.prototype.addLinkParam=function(t,e,i){if(!t.length){return"?"+e+"="+i}t=BX.Uri.removeParam(t,e);if(t.indexOf("?")!=-1){return t+"&"+e+"="+i}return t+"?"+e+"="+i};t.prototype.replaceAddressLink=function(t,e,i){if("history"in window){if(typeof window.history.pushState==="function"){e=e||this.getFilter().getSearch().getSearchString();e=e.replace(/[\\]+/gi,"/");i=i||this.getFilter().getFilterFieldsValues();var s={path:e,filter:i};if(t){t=this.addLinkParam(t,"tabId",this.tabId);window.history.pushState(s,null,t)}else{t=this.getCurrentUrl();t=this.addLinkParam(t,"tabId",this.tabId);window.history.replaceState(s,null,t)}}}};t.prototype.getCurrentUrl=function(){return window.location.protocol+"//"+window.location.hostname+(window.location.port!=""?":"+window.location.port:"")+window.location.pathname+window.location.search};t.prototype.onPopState=function(t){var e=t.state||window.history.state;if(!e||!e.path||!e.filter){window.location.reload()}};var i;t.prototype.getGrid=function(){if(typeof i!=="object"||typeof i.instance!=="object"||!i.instance instanceof BX.Main.grid){if(this.gridId!==""&&BX(this.gridId)&&typeof BX.Main.gridManager!=="undefined"){i=BX.Main.gridManager.getById(this.gridId)}}if(typeof i==="object"&&typeof i.instance==="object"&&i.instance instanceof BX.Main.grid){return i.instance}return null};t.prototype.onBeforeGridRequest=function(t,e){if(e.method=="POST"){if(!BX.type.isPlainObject(e.data)){e.data={}}e.data.viewMode=this.viewMode.join(",");e.data.tabId=this.tabId;e.data.path=this.getCurrentPath();e.data.AJAX_CALL="Y";if(this.mode=="admin"){e.data.admin_section="Y";e.data.lang=BX.message("LANGUAGE_ID")}}else{e.url=BX.Uri.removeParam(e.url,["viewMode","tabId","path"]);e.url=BX.Uri.addParam(e.url,{viewMode:this.viewMode.join(","),tabId:this.tabId,path:this.getCurrentPath()});if(this.mode=="admin"){e.url=BX.Uri.addParam(e.url,{admin_section:"Y",lang:BX.message("LANGUAGE_ID")})}}};t.prototype.reloadGrid=function(){if(this.getGrid()){this.getGrid().reload()}};t.prototype.loadGrid=function(t,e){if(this.getGrid()){this.toggleGridLoader(true);if(!BX.type.isNotEmptyString(t)){t=this.relUrl}if(BX.type.isPlainObject(e)){this.getGrid().reloadTable("POST",e,BX.proxy(this.initGridLinks,this),t)}else{this.getGrid().reloadTable("GET",{},BX.proxy(this.initGridLinks,this),t)}}};t.prototype.getGridRow=function(t){return this.getGrid().getRows().getById(""+t)};t.prototype.markGridRowWait=function(t){for(var e,i=0;i<t.length;i++){e=this.getGridRow(t[i]);if(e){e.getNode().style.opacity=.5}}};t.prototype.markGridRowNormal=function(t){for(var e,i=0;i<t.length;i++){e=this.getGridRow(t[i]);if(e){e.getNode().style.opacity=1}}};t.prototype.removeGridRow=function(t){for(var e,i=0;i<t.length;i++){e=this.getGridRow(t[i]);if(e){e.getNode().remove()}}};t.prototype.loadGridParams=function(){var t=BX("bx-translate-list-params");if(t){if("dataset"in t){if("actionmode"in t.dataset){this.actionMode=t.dataset.actionmode;this.tabId=t.dataset.tabid}}}};t.prototype.initGridLinks=function(){var t=this.getGrid();if(t){var e=t.getContainer().querySelectorAll("."+this.STYLES.gridLink);for(var i=0;i<e.length;i++){BX.bind(e[i],"click",BX.proxy(this.linkGridClick,this));BX.bind(e[i],"mousedown",BX.proxy(this.linkGridClick,this))}e=t.getContainer().querySelectorAll("."+this.STYLES.startIndexLink);for(i=0;i<e.length;i++){BX.bind(e[i],"click",function(){BX.UI.StepProcessing.ProcessManager.get("index").showDialog()})}}};t.prototype.linkGridClick=function(t){var e=t.ctrlKey||t.shiftKey||t.metaKey;var i=BX.getEventButton(t)===BX.MSLEFT;if(i){var s,n,r,a;if(BX.hasClass(t.currentTarget,this.STYLES.gridLink)){s=t.currentTarget}else{s=t.currentTarget.closest("."+this.STYLES.gridLink)}if(s){n=s.href;if(BX.type.isNotEmptyString(n)){if(e){window.open(n)}else{if(this.getFilter()){r=s.closest(".main-grid-row[data-id]");a=BX.data(r,"path");if(BX.type.isNotEmptyString(a)){this.getFilter().getSearch().input.value=a}}this.getFilter().getApi().apply()}}}}return!i};t.prototype.rowGridClick=function(t){var e,i,s,n,r;n=this.getGrid().getRows().getById(t.rowId);if(t.action==="FILE_LIST"){if(n.node){e=n.node.querySelector("."+this.STYLES.gridLink)}if(e){s=e.href;if(BX.type.isNotEmptyString(s)){if(this.getFilter()){r=n.getDataset();if(BX.type.isNotEmptyString(r.path)){this.getFilter().getSearch().input.value=r.path}}this.getFilter().getApi().apply()}}}else if(t.action==="EDIT"){if(n.node){i=n.node.querySelector("."+this.STYLES.editLink)}if(i){s=i.href;if(BX.type.isNotEmptyString(s)){window.location.href=s}}}};t.prototype.toggleGridLoader=function(t){var e=this.getGrid();if(e){if(t){e.tableFade()}else{e.tableUnfade()}}};t.prototype.sendGridAction=function(t,e){this.toggleGridLoader(true)};t.prototype.remove=function(t){this.sendGridAction("remove",t)};t.prototype.getCurrentPath=function(){var t=this.getFilter().getSearch().getInput(),e=BX.type.isNotEmptyString(t.value)?t.value:this.defaults.startingPath;e=e.replace(/[\\]+/gi,"/");if(t.value!==e){t.value=e}return e};t.prototype.setPath=function(t){if(BX.type.isNotEmptyString(t)){if(this.getFilter()){this.getFilter().getSearch().input.value=t;this.getFilter().getApi().apply()}}};var s;t.prototype.showViewModeMenu=function(t){var e=t.currentTarget;if(!s){s=new BX.PopupMenuWindow("translate-view-mode-menu",e,[{id:this.VIEW_MODE.CountPhrases,text:this.getMessage("ViewModeMenuCountPhrases"),className:this.STYLES.menuItem+" translate-view-mode-counter "+(this.viewMode.indexOf(this.VIEW_MODE.CountPhrases)>=0?this.STYLES.menuItemChecked:""),onclick:this.setViewMode.bind(this,this.VIEW_MODE.CountPhrases,{fellowClass:"translate-view-mode-counter",title:this.getMessage("ViewModeTitleCountPhrases")})},{id:this.VIEW_MODE.CountFiles,text:this.getMessage("ViewModeMenuCountFiles"),className:this.STYLES.menuItem+" translate-view-mode-counter "+(this.viewMode.indexOf(this.VIEW_MODE.CountFiles)>=0?this.STYLES.menuItemChecked:""),onclick:this.setViewMode.bind(this,this.VIEW_MODE.CountFiles,{fellowClass:"translate-view-mode-counter",title:this.getMessage("ViewModeTitleCountFiles")})},{id:this.VIEW_MODE.UntranslatedPhrases,text:this.getMessage("ViewModeMenuUntranslatedPhrases"),className:this.STYLES.menuItem+" translate-view-mode-counter "+(this.viewMode.indexOf(this.VIEW_MODE.UntranslatedPhrases)>=0?this.STYLES.menuItemChecked:""),onclick:this.setViewMode.bind(this,this.VIEW_MODE.UntranslatedPhrases,{fellowClass:"translate-view-mode-counter",title:this.getMessage("ViewModeTitleUntranslatedPhrases")})},{id:this.VIEW_MODE.UntranslatedFiles,text:this.getMessage("ViewModeMenuUntranslatedFiles"),className:this.STYLES.menuItem+" translate-view-mode-counter "+(this.viewMode.indexOf(this.VIEW_MODE.UntranslatedFiles)>=0?this.STYLES.menuItemChecked:""),onclick:this.setViewMode.bind(this,this.VIEW_MODE.UntranslatedFiles,{fellowClass:"translate-view-mode-counter",title:this.getMessage("ViewModeTitleUntranslatedFiles")})},{delimiter:true},{id:this.VIEW_MODE.HideEmptyFolders,text:this.getMessage("ViewModeMenuHideEmptyFolders"),className:this.STYLES.menuItem+" translate-view-mode-emptiness "+(this.viewMode.indexOf(this.VIEW_MODE.HideEmptyFolders)>=0?this.STYLES.menuItemChecked:""),onclick:this.setViewMode.bind(this,this.VIEW_MODE.HideEmptyFolders)},{id:this.VIEW_MODE.ShowDiffLinks,text:this.getMessage("ViewModeMenuShowDiffLinks"),className:this.STYLES.menuItem+" translate-view-mode-difflinks "+(this.viewMode.indexOf(this.VIEW_MODE.ShowDiffLinks)>=0?this.STYLES.menuItemChecked:""),onclick:this.setViewMode.bind(this,this.VIEW_MODE.ShowDiffLinks)}],{autoHide:true,autoClose:true,closeByEsc:true})}s.bindElement=e;s.show()};t.prototype.setViewMode=function(t,e){e=e||{};var i=BX.type.isNotEmptyString(e.fellowClass),n=false;var r=BX.type.isNotEmptyString(e.title);var a,o,d=s.getMenuItems();if(!Array.prototype.removeVal){Array.prototype.removeVal=function(t){var e=this.indexOf(t);if(e!==-1)this.splice(e,1)}}if(i){if(this.viewMode.indexOf(t)<0){n=true;for(a in d){if(!d.hasOwnProperty(a))continue;o=d[a];if(!BX.type.isNotEmptyString(o.className)){continue}if(o.className.indexOf(e.fellowClass)<0){continue}this.viewMode.removeVal(o.id)}this.viewMode.push(t)}}else{n=true;if(this.viewMode.indexOf(t)<0){this.viewMode.push(t)}else{this.viewMode.removeVal(t)}}for(a in d){if(!d.hasOwnProperty(a))continue;o=d[a];if(this.viewMode.indexOf(o.id)<0){BX.removeClass(o.layout.item,this.STYLES.menuItemChecked)}else{BX.addClass(o.layout.item,this.STYLES.menuItemChecked)}}if(r){s.bindElement.innerHTML=e.title}if(n){setTimeout(BX.delegate(function(){this.getFilter().getApi().apply()},this),200)}if(s){s.close()}};var n;var r;t.prototype.showExtraMenu=function(t){var e=t.currentTarget;if(!n){n=new BX.PopupMenuWindow("translate-extra-menu",e,r,{autoHide:true,autoClose:true,closeByEsc:true})}n.bindElement=e;n.show()};var a;t.prototype.showInitFolderMenu=function(t){var e=t.currentTarget;if(!a){var i=[];for(var s=0;s<this.defaults.initFolders.length;s++){i.push({id:"translate-init-folder-"+s,text:this.defaults.initFolders[s],className:this.STYLES.menuItem+" "+(this.defaults.startingPath===this.defaults.initFolders[s]?this.STYLES.menuItemChecked:""),onclick:this.setInitFolder.bind(this,this.defaults.initFolders[s])})}a=new BX.PopupMenuWindow("translate-init-folder-menu",e,i,{autoHide:true,autoClose:true,closeByEsc:true})}a.bindElement=e;a.show()};t.prototype.setInitFolder=function(t){var e,i,s=a.getMenuItems();for(e in s){if(!s.hasOwnProperty(e))continue;i=s[e];if(i.text===t){BX.addClass(i.layout.item,this.STYLES.menuItemChecked)}else{BX.removeClass(i.layout.item,this.STYLES.menuItemChecked)}}if(a){a.close()}this.setPath(t)};var o={};t.prototype.addGroupAction=function(t,e){o[t]=e};t.prototype.callGroupAction=function(){var t=this.getGrid(),e=t.getActionsPanel(),i=e.getSelectedIds(),s=e.getValues(),n=s.action_button,r=t.getRows(),a=[],d=[],l,h;if(i.length>0){for(var f in i){l=r.getById(i[f]);if(l){h=l.getDataset();if(h){if("path"in h){a.push(h.path)}if("code"in h){d.push(h.code)}}}}if(typeof o[n]==="function"){o[n].apply(this,[a,d])}}};t.prototype.radioOnMultiple=function(t,e,i,s){var n=this.getFilter(),r=t.input.closest(".main-ui-control.main-ui-multi-select"),a=n.getApi();if(!BX.isParentForNode(n.getFilter(),t.input)){return}if(r){if(BX.data(r,"name")==i){var o,d;d=n.getFilterFieldsValues();o=BX.clone(d[i]);d[i]={};for(var l in s){if(!s.hasOwnProperty(l))continue;if(s[l].indexOf(e.VALUE)>=0){for(var h in o){if(!o.hasOwnProperty(h))continue;if(s[l].indexOf(o[h])>=0){if(e.VALUE!=o[h]){delete o[h]}}}}}d[i]=o;a.setFields(d)}}};BX.Translate.PathList=new t})(window);
//# sourceMappingURL=script.map.js